﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using System.Web.Http.Description;
using CSharpDay13Nov10.Data;
using CSharpDay13Nov10.Data.Model;
using CSharpDay13Nov10.Adapters.Interfaces;
using CSharpDay13Nov10.Adapters.Adapters;
using Microsoft.AspNet.Identity;
using CSharpDay13Nov10.Models; //used for GetUserId()

namespace CSharpDay13Nov10.Controllers
{
    [Authorize]
    public class apiToDoesController : ApiController
    {
        IToDoAdapter _adapter;
        public apiToDoesController()
        {
            _adapter = new ToDoAdapter();
        }
        public apiToDoesController(IToDoAdapter adapter)
        {
            _adapter = adapter;
        }
        public IHttpActionResult Get()
        {
            string user = User.Identity.GetUserId();
            List<ToDoVM> model;
            if (User.IsInRole("User"))
            {
                model = _adapter.GetAllToDo(user);
            }
            else if (User.IsInRole("Admin"))
            {
                model = _adapter.GetAllToDoAdmin();
            }
            else
            {
                model = new List<ToDoVM>();
            }
            return Ok(model);
        }
    }
}